<template>
    <div>
        <h3>医生信息添加</h3>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">医生</td>
                    <td><input type="text" v-model="arr.doctorName" /></td>
                </tr>
                <tr>
                    <td align="right">科室</td>
                    <td>
                        <select v-model="arr.doctorKeShiId">
                            <option value="">请选择</option>
                            <option v-for="item in brr" :value="item.keShiId">{{ item.keShiName }}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align="right">职称</td>
                    <td>
                        <select v-model="arr.doctorZhiCheng">
                            <option value="">请选择</option>
                            <option value="主治医师">主治医师</option>
                            <option value="护士">护士</option>
                            <option value="护士长">护士长</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align="right">第一执业医师</td>
                    <td><input type="text" v-model="arr.doctorYiYuan" /></td>
                </tr>
                <tr>
                    <td align="right">是否开通账号</td>
                    <td>
                        <input type="radio" value="true" v-model="arr.shiFou" />已开通
                        <input type="radio" value="false" v-model="arr.shiFou" />未开通

                    </td>
                </tr>

                <tr>
                    <td align="right">图片</td>
                    <td><input type="file" @change="img" />
                        <img :src="arr.ddctorType" width="60" height="60" v-if="arr.ddctorType != ''" />
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="添加" @click="ok" /></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { reactive, ref, onMounted } from 'vue';
import axios from 'axios';
import { useRoute, useRouter } from 'vue-router';

let u = useRouter();

let arr: any = ref({
    "doctorName": "",
    "doctorKeShiId": "",
    "doctorZhiCheng": "",
    "doctorYiYuan": "",
    "shiFou": true,
    "ddctorType": "",
    "isDel": true
});

const ok = () => {
    console.log(arr.value);

    axios({
        url: "https://localhost:7107/api/Doctor/DoctorAdd",
        data: arr.value,
        method: "post"
    })
        .then(res => {
            if (res.data > 0) {
                alert('添加成功');
                u.push("/DoctorShow");
            }
            else {
                alert('添加失败');
            }
        }

        )
}

const img = (e: any) => {
    let obj = e.target.files[0];
    let f = new FormData();
    f.append("file", obj);



    axios({
        url: "https://localhost:7107/api/img/Imgs",
        method: "post",
        data: f
    })
        .then(res => {
            arr.value.ddctorType = res.data;
        })
}

let brr: any = ref([]);

onMounted(() => {
    Fan();
})
const Fan = () => {




    axios({
        url: "https://localhost:7107/api/Doctor/Bind",
        method: "get",
    })
        .then(res => {
            brr.value = res.data;
        })
}
</script>

<style scoped></style>